package compilers;

/**
 * @program: javase
 * @description:
 * @author: lld
 * @create: 2021-04-29 16:23
 **/
public class ComperOperator {
    public char comperOperator(char operator1, char operator2) {
        char result = '?';
        switch (operator1) {
            case '+':
            case '-':
                switch(operator2) {
                    case '+':
                    case '-':
                    case ')':
                    case '#':
                        result = '>';
                        break;
                    case '*':
                    case '/':
                    case '(':
                        result = '<';
                        break;
                }
                break;
            case '*':
            case '/':
                switch(operator2) {
                    case '+':
                    case '-':
                    case '*':
                    case '/':
                    case ')':
                    case '#':
                        result = '>';
                        break;
                    case '(':
                        result = '<';
                        break;
                }
                break;
            case '(':
                switch(operator2) {
                    case '+':
                    case '-':
                    case '*':
                    case '/':
                    case '(':
                        result = '<';
                        break;
                    case ')':
                        result = '=';
                        break;
                    case '#':
                        result = '?'; // 右括号后不能是#
                }break;
            case ')':
                switch(operator2) {
                    case '+':
                    case '-':
                    case '*':
                    case '/':
                    case ')':
                    case '#':
                        result = '>';
                        break;
                    case '(':
                        result = '?';  //右括号后面跟左括号，非法
                        break;
                }break;
            case '#':
                switch(operator2) {
                    case '+':
                    case '-':
                    case '*':
                    case '/':
                    case '(':
                        result = '<';
                        break;
                    case ')':
                        result = '?';  //#后面不能跟右括号
                        break;
                    case '#':
                        result = '=';
                        break;
                }break;
            default:
                break;
        }
        return result;
    }
}
